using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace Impact.Web.Foundation.Controls
{

    /// <summary>
    /// a subclass of dropdownlist that allows for a default value to bind to
    /// </summary>
    public class SelectableDropDownList : DropDownList
    {
        private string selectedValue;

        /// <summary>
        /// override of the data bound event so that we can select the value provided by
        /// the user
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDataBound(EventArgs e)
        {
            base.OnDataBound(e);

            SelectDefaultValue();
        }

        private void SelectDefaultValue()
        {
            if (!string.IsNullOrEmpty(selectedValue))
            {
                ListItem selectedItem = this.Items.FindByValue(selectedValue);
                if (selectedItem != null)
                {
                    selectedItem.Selected = true;
                }
            }
        }

        /// <summary>
        /// Gets or Sets the value that should selected by default
        /// </summary>
        public string DefaultSelectedValue
        {
            get { return selectedValue; }
            set { selectedValue = value; }
        }



    }
}
